import java.util.Stack;

import static java.util.Optional.empty;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2023-02-15
 * Time: 8:54
 */
public class MyQueue { //栈实现队列
    public Stack<Integer> stack1;
    public Stack<Integer> stack2;//两个栈
    public MyQueue(){
        stack1 = new Stack<>();
        stack2 = new Stack<>();

    }
    public void push(int x){
        stack1.push(x);
    }
    public int pop(){
        if(empty()){
            return -1;
        }
        if(stack2.empty()){ //如果2栈为空，弹出第一个栈里面的所有元素
            while(!stack1.empty()){
                stack2.push(stack1.pop());//都放到这里面
            }
        }
        return stack2.pop();//只出第二个栈的栈顶元素
    }
    public int peek(){
        if(empty()){
            return -1;
        }
        if(stack2.empty()){
            while (!stack1.empty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }
    public boolean empty(){
        return stack1.empty() && stack2.empty();
        //第一个栈为空，第二个也为空，则说明此时的队列为空
    }

}
